package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;
    /**
     * 查询评论列表
     * */
    @GetMapping
    public ResponseEntity comments(@RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize,
                                   String movementId){
        PageResult vo = commentsService.comments(movementId,page,pagesize);
        return ResponseEntity.ok(vo);

    }
    /**
     * 提交评论
     * */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){
        String movementId = map.get("movementId").toString();
        String comment = map.get("comment").toString();
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论-点赞
     *
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){

       Integer count = commentsService.like(id);
       return ResponseEntity.ok(count);
    }
    /**
     * 评论-取消点赞
     *
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String id){

       Integer count = commentsService.dislike(id);
       return ResponseEntity.ok(count);
    }
}
